package com.problem.leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author didi
 * @DESCRIPTION
 * @create 2019-05-06 10:49
 **/

public class Problem884 {
    public String[] uncommonFromSentences(String A, String B) {
        HashMap<String, Integer> hashSet = new HashMap<>();
        String[]                 strings = A.split(" ");
        for (String ele : strings) {
            if (!ele.trim().isEmpty()) {
                if (!hashSet.containsKey(ele)) {
                    hashSet.put(ele, 1);
                } else {
                    hashSet.put(ele, hashSet.get(ele) + 1);
                }
            }
        }

        String[] tmp = B.split(" ");
        for (String ele : tmp) {
            if (!ele.trim().isEmpty()) {
                if (!hashSet.containsKey(ele)) {
                    hashSet.put(ele, 1);
                } else {
                    hashSet.put(ele, hashSet.get(ele) + 1);
                }
            }
        }
        List<String> result = new ArrayList<>();
        for (Map.Entry<String, Integer> entry : hashSet.entrySet()) {
            if (entry.getValue() == 1) {
                result.add(entry.getKey());
            }
        }

        return result.toArray(new String[]{});
    }
}
